<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./demo3.js"></script>

</head>

<body>

    <img id="light" src="../img/a.jpg"> <br>
    <div class="cls">传智教育</div> <br>
    <div class="cls">黑马程序员</div> <br>
    <input type="checkbox" name="hobby"> 电影
    <input type="checkbox" name="hobby"> 旅游
    <input type="checkbox" name="hobby"> 游戏
    <input type="button" onclick="on()">
    <input type="button" id="btn">
    <input type="button" value="获取数据" onclick="getData()">

    <br>
</body>
    <script>
        //在此处书写js代码
        // var img = document.getElementById("light");
        // alert(img);


        // var divs = document.getElementsByTagName("div");

        // for(let i = 0;i <divs.length; i++){
        //     alert(divs[i]);
        // }
        // var hobbys = document.getElementsByName("hobby");
        // for (let i = 0; i < hobbys.length; i++) {
        //     alert(hobbys[i]);
        // }

        // var clss = document.getElementsByClassName("cls");
        // for (let i = 0; i < clss.length; i++) {
        //     alert(clss[i]);
        // }
        // function on(){
        //     alert("我被点及了");
        // }
        // document.getElementById("btn").onclick = function(){
        //     alert("DAsdas");
        // }
        function getData() {
            //1.创建XMLHttpRequest
            var xmlHttpRequest = new XMLHttpRequest();
            //2.发送异步请求
            xmlHttpRequest.open('GET', 'https://mock-java.itheima.net/mock/13530/emp/list');
            xmlHttpRequest.send(); //发送请求
            //获取服务相应数据
            xmlHttpRequest.onreadystatechange = function () {
                if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
                    alert(xmlHttpRequest.responseText)
                }
            }

        }
    </script>


</html>